<?php
require_once("classes/MySQLdatabase.php");

class User extends Database{
     
    public function createUser($name,$username,$email,$password){
        $this->connectDatabase();
        
        $sQuery = "INSERT INTO account(username,password)
                    VALUES('$username',md5('$password'))";
        mysql_query($sQuery);
        
        $row = mysql_fetch_array(mysql_query("SELECT account_id FROM account WHERE username = '$username' AND password = md5('$password')"));
        $id = $row['account_id'];
        
        $sQuery = mysql_query("UPDATE account SET user_id='$id' WHERE account_id = '$id'");
        
        $sQuery = "INSERT INTO user_info(name,email,account_id)
                    VALUES('$name','$email','$id')";
        mysql_query($sQuery);
    }
    
    public function loginUser($username,$pass){
        $this->connectDatabase();
        
        $sQuery = "SELECT * FROM account WHERE username='$username' AND password=md5('$pass')";
        $result = mysql_query($sQuery);
        $ctr = 0;
        $row = mysql_fetch_row($result);
        if(!isset($row)){
            $row = null;
        }
        return $row;
    
    }
}
?>